package com.ourteam.frame.util;

import java.util.concurrent.CountDownLatch;

abstract public class WorkThread extends Thread {

	private CountDownLatch countDownLatch;

	public WorkThread(CountDownLatch latch) {
		this.countDownLatch = latch;
	}

	public CountDownLatch getCountDownLatch() {
		return countDownLatch;
	}

	public void run() {
		try {
			long start = System.currentTimeMillis();
			doWork();
			System.out.println(
					Thread.currentThread().getName() + " Time " + (System.currentTimeMillis() - start) / 1000 + "s");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			countDownLatch.countDown();
		}

	}

	abstract protected void doWork() throws Exception;
}
